{layout name="public/layout" /}
{include file='yxnavbar'}


<div class="main">
    {include file='demo/game_common_nav'}
    <div class="panel panel-default" role="tabpanel">
        <div class="panel-heading">问题设置</div>
        <div class="panel-body">
            <form action="" method="post" class="form-horizontal" role="form" name="form2" id="form2">
                <input type="hidden" name="q_id" value="{$item['q_id']}"/>
                <input type="hidden" name="themeid" value="{$themeid}"/>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>问题描述</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="text" class="form-control"  id="question" placeholder="" name="question"  value="{$item['question']}">
                        <span class="help-block">示例：甲骨文是写在什么上面？ </span>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>A选项答案：</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="text" class="form-control"  id="first" placeholder="" name="first"  value="{$item['first']}">
                        <span class="help-block">示例： 鱼骨</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>B选项答案：</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="text" class="form-control"  id="second" placeholder="" name="second"  value="{$item['second']}">
                        <span class="help-block">示例： 石壁</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>C选项答案：</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="text" class="form-control"  id="third" placeholder="" name="third"  value="{$item['third']}">
                        <span class="help-block">示例： 龟骨</span>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label"><span style="color: red;">*</span>正确选项：</label>
                    <div class="col-sm-8 col-xs-12">
                        <div class="input-group">
                            <select class="form-control" name="sure_method">
                                <option value="0" {if empty($item['sure_method']) }selected="selected"{/if}>----------默认不显示----------</option>
                                <option value="1" {if $item['sure_method'] == 1 }selected="selected"{/if}>选项A</option>
                                <option value="2" {if $item['sure_method'] == 2 }selected="selected"{/if}>选项B</option>
                                <option value="3" {if $item['sure_method'] == 3 }selected="selected"{/if}>选项C</option>
                            </select>

                        </div>

                    </div>
                </div>


                <div class="form-group" id="sub_upload" >
                    <div class="col-sm-12">
                        <input name="submit" onclick="addOrEditLtItem()" id="btnConfirm" type="button" value="提交" class="btn btn-primary col-lg-2">
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(
        function (){
        }
    );
    function drop_confirm(msg, url){
        if(confirm(msg)){
            window.location = url;
        }
    }
    //新增\修改 提交数据
    function addOrEditLtItem() {
        var question = $("#question").val();
        var first = $("#first").val();
        var second = $("#second").val();
        var third = $("#third").val();
        var sure_method = $("#sure_method").val();
        if (!question){
            layer.msg('问题描述不能为空');
            return
        }
        if (!first){
            layer.msg('选项A的答案不能为空');
            return;
        }
        if (!second){
            layer.msg('选项B的答案不能为空');
            return;
        }
        if (!third){
            layer.msg('选项C的答案不能为空');
            return;
        }
        console.log(sure_method)
        if (sure_method==0){
            layer.msg('正确选项未选择');
            return;
        }
        let postUrl = "{php echo createWebUrlPlugin('demo/edit');}";
        let success_redirect = "{php echo createWebUrlPlugin('demo',array('themeid'=>$themeid));}";
        let formData = $("#form2").serialize();
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:formData,
            success:function (e) {
                let status = e.status;
                if (status!=1){
                    layer.msg('操作失败')
                }else{
                    layer.msg('操作成功');
                    window.location.href = success_redirect;
                }

            },
            fail:function (err) {
                console.log(err)
            }
        })
    }
</script>
